<!--底部按钮-->
<div ng-show="pagedata.showcarts" class="popup">
			<div class="popup-body">
			<div class="popup-bottom">
				<div class="fui-cell-group" style="margin-top:0;padding-top:1rem;margin-bottom:3.6rem">
					<i ng-click="pagedata.showcarts=false" class="closed icon icon-close red" style="font-size:1rem;color:red"></i>
					<div class="fixed-title">
							 <span class="befirst spacing">
								<span class="icon icon-icon-xiexiantiao" style="color:#fa1608"></span>
								<span class="icon icon-icon-xiexiantiao" style="color:#fb6b61"></span>
								<span class="icon icon-icon-xiexiantiao" style="color:#fdcecb"></span>
							 </span> 
							 <span class="title-text">我的菜篮子</span> 
							 <span class="spacing">
								 <span class="icon icon-icon-xiexiantiao" style="color:#fdcecb"></span>
								 <span class="icon icon-icon-xiexiantiao" style="color:#fb6b61"></span>
								 <span class="icon icon-icon-xiexiantiao" style="color:#fa1608"></span>
							 </span>
					</div>
					<div ng-repeat="item in pagedata.carts" ng-if="item.total>0" class="fui-cell">
							<div class="fui-cell-text">
								{{item.title}}<span class="subtitle" ng-if="item.optiontitle">({{item.optiontitle}})</span>
							</div>
							<div class="fui-cell-remark noremark">
								<span class="r-f red" style="margin-right:1rem">￥ {{item.price * item.total}} /{{item.unit ||'件'}}<span style="font-size:0.6rem;color:#999" ng-if="item.weight>0">（{{item.weight}}kg）</span></span>
							</div>
							<div class="fui-cell-remark noremark">
								<span class="fui-number small r-f" style="right:0;margin-top:0.3rem">
									<span class="minus" ng-click="pagedata.cart_minus(item)"><i class="icon icon-subtract" style="font-size:0.7rem"></i></span>
										<input ng-if="item.total>0" class="num shownum" type="text" ng-model="item.total" style="width:1rem" ng-change="pagedata.refresh()"/>
									<span class="plus" ng-click="pagedata.cart_plus(item)"><i class="icon icon-tianjia" style="font-size:0.7rem"></i></span>
								</span>
							</div>
					</div>
				</div>
				<div class="fui-navbar-tip"><red>￥{{pagedata.showprice || '0.00'}}</red>不是最终优惠金额，具体价格以最终下单为准！</div>
				<div class="fui-navbar bottom-buttons">
					<a class="nav-item external" href="javascript:" ng-click="access_json('jy_pigtuan/index/')">
						<span class="icon icon-dianpu"></span>
						<span class="label">首页</span>
					</a>
					<a class="nav-item external" href="javascript:" ng-click="pagedata.showcarts=true">
						<div ng-if="pagedata.cartnums>0" class="badge in">{{pagedata.cartnums}}</div>
						<span class="icon icon-tianmaochaoshigouwuche"></span>
						<span class="label">购物车</span>
					</a>
					<a class="nav-item btn buybtn" ng-click="pagedata.check_buy()" style="line-height:1.4;padding-top:0.3rem" >
						<span>¥ <strong>{{pagedata.showprice}}</strong><span style="font-size:0.5rem">(未优惠)</span></span>
						<span class="label" style="color:#fff;font-size:0.75rem">去支付</span>
					</a>
				</div>
			</div>
			</div>
</div>
<div class="fui-navbar-tip"><red>￥{{pagedata.showprice || '0.00'}}</red>不是最终优惠金额，具体价格以最终下单为准！</div>
<div class="fui-navbar bottom-buttons">
	<a ng-class="{'external nav-item':1,'active':show_active('jy_pigtuan/index/')}" href="javascript:" ng-click="access_json('jy_pigtuan/index/')">
        <span class="icon icon-dianpu"></span>
        <span class="label">首页</span>
    </a>
	<a class="nav-item external" href="javascript:" ng-click="pagedata.showcarts=true">
		<div ng-if="pagedata.cartnums>0" class="badge in">{{pagedata.cartnums}}</div>
        <span class="icon icon-tianmaochaoshigouwuche"></span>
        <span class="label">购物车</span>
    </a>
	<a class="nav-item btn buybtn" ng-click="pagedata.check_buy()" style="line-height:1.4;padding-top:0.3rem" >
		<span>¥ <strong>{{pagedata.showprice}}</strong><span style="font-size:0.5rem">(未优惠)</span></span>
		<span class="label" style="color:#fff;font-size:0.75rem">去支付</span>
	</a>
</div>
<script>
//刷新总数和总价
scope.pagedata.cart_refresh=function(){
	var cartnums=0;
	var totalprice=0
	angular.forEach(scope.pagedata.carts,function(cart){
		cartnums+=parseInt(cart.total);
		totalprice+=cart.total*cart.price;
	});
	scope.pagedata.cartnums=cartnums;
	console.log(scope.pagedata.cartnums);
	scope.pagedata.totalprice=totalprice;
	scope.pagedata.showprice=scope.price(scope.pagedata.totalprice);
	scope.$evalAsync();
}
scope.pagedata.getcarts=function(){
	scope.get('jy_pigtuan/member.cart/getlist/selected=1',function(res){
		scope.pagedata.carts=res.list
		scope.pagedata.cart_refresh();
		scope.$evalAsync();
	});
}
scope.pagedata.getcarts();
//减少
scope.pagedata.cart_minus=function(g){
	g.carttotal=g.total
	g.cartid=g.id
	g.id=g.goodsid
	if(g.carttotal<=0){
		return false;
	}
	scope.post_json('jy_pigtuan/member.cart/minus/selected=1',{'getlist':true,'id':g.cartid},function(res){
			g.carttotal--;
			g.total--
			for (j = 0; j < scope.pagedata.list.length; j++) {
						if(scope.pagedata.list[j].id==g.id){
							scope.pagedata.list[j].carttotal=g.total
						}
			}
			scope.pagedata.carts=res.list
			scope.pagedata.cart_refresh();
			
	});
}
//增加
scope.pagedata.cart_plus=function(g){
	g.carttotal=g.total
	g.id=g.goodsid
	if(g.optionid>0){
			if(g.carttotal>=g.options.stock){
				scope.message('不能再添加了，已超过库存！','error');
				return false;
			}
	}else{
			if(g.carttotal>=g.goodstotal){
				scope.message('不能再添加了，已超过库存！','error');
				return false;
			}
	}	
	scope.post_json('jy_pigtuan/member.cart/addtocart/selected=1',{'getlist':true,'goodsid':g.id,'optionid':g.optionid},function(res){
			g.carttotal++;
			g.total++
			var category=scope.pagedata.category
				for (j = 0; j < scope.pagedata.list.length; j++) {
						if(scope.pagedata.list[j].id==g.id){
							scope.pagedata.list[j].carttotal=g.total
						}
				}
			if(res!='success'){
				g.cartid=res.id;
				scope.pagedata.carts=res.list
			}
			scope.pagedata.cart_refresh();
	});
}
scope.pagedata.check_buy=function(){
	scope.get('jy_pigtuan/member.cart/check_buy/',function(res){});
}
</script>